package org.example.application;

import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.example.domain.service.LoginDomainService;
import org.example.domain.system.model.req.UserLoginReq;
import org.example.utils.JwtUtils;
import org.example.utils.SecurityUtil;
import org.example.web.result.ResultInfo;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class LoginService {
    private final LoginDomainService loginDomainService;


    public ResultInfo login(UserLoginReq userLoginReq) {
        return loginDomainService.login(userLoginReq);
    }

    public ResultInfo logout(HttpServletRequest request) {
        String token = SecurityUtil.getToken(request);
        String loginType = JwtUtils.getLoginType(token);
        return loginDomainService.logout(token, loginType);
    }

    public ResultInfo refresh(HttpServletRequest request) {
        String token = SecurityUtil.getToken(request);
        String loginType = JwtUtils.getLoginType(token);
        return loginDomainService.refresh(token, loginType);
    }
}
